package com.whut.mobilesafe.service;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;

import com.whut.mobilesafe.engine.ProcessInfoProvider;

/**
 * 作    者:yubo.xiaoyubo
 * 时    间：2015/12/30 19:54
 * 版    本：1.0
 * 描    述：
 */
public class AutoKillService extends Service {

    private InnerBroadCastAutoKillReceiver mInnerBroadCastAutoKillReceiver;

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    /**
     * 要做的事情，监听锁屏广播
     * 当一收到锁屏的广播之后，就去清理
     */

    @Override
    public void onCreate() {
        super.onCreate();
        mInnerBroadCastAutoKillReceiver = new InnerBroadCastAutoKillReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_SCREEN_OFF);
        //注册监听屏幕关闭的广播
        registerReceiver(mInnerBroadCastAutoKillReceiver, filter);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mInnerBroadCastAutoKillReceiver != null) {
            unregisterReceiver(mInnerBroadCastAutoKillReceiver);
            mInnerBroadCastAutoKillReceiver = null;
        }
    }


    class InnerBroadCastAutoKillReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d("InnerBroadCastAutoKillR", "锁屏啦了啊，开始清理了");
            ProcessInfoProvider.killAll(context);
        }

    }
}
